
function comAddSelectValueSelect2Fnc(selectObj, actionFlg, inTrxObj, firstSpace, star){
    $(selectObj).empty();
    //var inTrxObj = {
    //    trx_id      : 'XPCONDITION' ,
    //    action_flg : actionFlg      ,
    //    iary        : [iary]
    //};
    inTrxObj["trx_id"] = "XPCONDITION";
    inTrxObj["action_flg"] = actionFlg;
    var  outTrxObj = comTrxSubSendPostJson(inTrxObj);
    console.log(outTrxObj);
    if( outTrxObj.rtn_code == "0000000" ) {
        if(firstSpace === true){
            $(selectObj).append("<option ></option>");
        }
        if(star === true){
            $(selectObj).append("<option value="+ "*" +">"+ "*" +"</option>")
        }
        var tbl_cnt = comParseInt( outTrxObj.tbl_cnt);
        if( tbl_cnt == 1 ){
            $(selectObj).append("<option value="+ outTrxObj.oary[0]['value']+">"+ outTrxObj.oary[0]['text'] +"</option>");
        }else if(tbl_cnt>1){
            for(var i=0;i<tbl_cnt;i++){
                $(selectObj).append("<option value="+ outTrxObj.oary[i]['value'] +">"+ outTrxObj.oary[i]['text'] +"</option>");
            }
        }
        $(selectObj).select2({
           theme : "bootstrap"
        });
    }
    $(selectObj).val("");
    $(selectObj).select2({theme : "bootstrap"});
}


function comAddSelectValueFnc(selectObj, actionFlg, inTrxObj, firstSpace, star){
    $(selectObj).empty();
    //var inTrxObj = {
    //    trx_id      : 'XPCONDITION' ,
    //    action_flg : actionFlg      ,
    //    iary        : [iary]
    //};
    inTrxObj["trx_id"] = "XPCONDITION";
    inTrxObj["action_flg"] = actionFlg;
    var  outTrxObj = comTrxSubSendPostJson(inTrxObj);
    console.log(outTrxObj);
    if(  outTrxObj.rtn_code == "0000000" ) {
        if(firstSpace === true){
            $(selectObj).append("<option ></option>");
        }
        if(star === true){
            $(selectObj).append("<option value="+ "*" +">"+ "*" +"</option>")
        }
        var tbl_cnt = comParseInt( outTrxObj.tbl_cnt);
        if( tbl_cnt == 1 ){
            $(selectObj).append("<option value="+ outTrxObj.oary[0]['value']+">"+ outTrxObj.oary[0]['text'] +"</option>");
        }else if(tbl_cnt>1){
            for(var i=0;i<tbl_cnt;i++){
                $(selectObj).append("<option value="+ outTrxObj.oary[i]['value'] +">"+ outTrxObj.oary[i]['text'] +"</option>");
            }
        }
        //$(selectObj).select2({
        //    theme : "bootstrap"
        //});
    }
    //$(selectObj).val("");
    //$(selectObj).select2({theme : "bootstrap"});
}



function comTrxSubSendPostJson(inObj, async) {
    if (async == undefined || async != true) {
        async = false;
    }
    console.info(inObj);
    var begin = new Date(), end;
    var url = "sendMessage.do";
    var strInTrx = JSON.stringify(inObj);  //把对象、数组等转化成JSON
    var outObj = null,
        $ajaxOverlay = $('#ajaxOverlay');
    $.ajax(url, {
        type: "post",
        url: url,
        timeout: 120000,
        data: {
            trxId: inObj.trx_id,   //service映射ID
            strInTrx: strInTrx
        },
        async: async,
        beforeSend: function () {
            $ajaxOverlay.show();
        },
        complete: function () {
            $ajaxOverlay.hide();
        }
    }).done(function (data) {
        // console.info("done:" + data);
        if (data.indexOf("<title>用户登录</title>") > 0) window.location.href="goto?page=login-lte";
        outObj = JSON.parse(data);//JSON.parse()把对象转换成字符串。是JS方法。
        var rtn_code = outObj.rtn_code;
        if (rtn_code != "0000000") {
            showErrorDialog(rtn_code, outObj.rtn_mesg);
            return false;
        }
    }).error(function (xhr) {
        showErrorDialog('请求失败','查询返回数据异常，请重试或联系管理员确认！');
        console.error(xhr);
    });

    end = new Date();
    //$.post("/client",{
    //    msg: 'comTrxSubSendPostJson '+ inObj.trx_id + ' cost: ' + (end - begin) + 'ms.'
    //});

    return outObj;
}


function ajax(url, inObj, async, callback) {
    if($("#startTime").val() === null || $("#startTime").val() === '' || $("#endTime").val() === null || $("#endTime").val() === ''){
        showMessengerDialog("时间日期为必选项"); return false;
    }

    if (async === 'undefined') async == false;
    console.info("inObj:" + inObj);
    var begin = new Date(), end;
    var strInTrx = JSON.stringify(inObj);  //把对象、数组等转化成JSON
    var outObj = null,
    $ajaxOverlay = $('#ajaxOverlay');
    $.ajax(url, {
        type: "post",
        url: url,
        timeout: 600000,
        data: {
            hashMapString: strInTrx
        },
        async: async,
        beforeSend: function () {
            $ajaxOverlay.show();
        },
        complete: function () {
            $ajaxOverlay.hide();
        }
    }).done(function (data) {
        // console.info("done:" + data);
        if (data.indexOf("<title>用户登录</title>") > 0) window.location.href="goto?page=login-lte";

        outObj = JSON.parse(data);
        callback(outObj);
        return outObj;

        if (outObj.rtn_code == "0000000") {
            if (typeof callback === "function") callback(outObj);
        } else {
            showErrorDialog(outObj.rtn_code, outObj.rtn_mesg);
        }
    }).error(function (xhr,status) {
        if(status=='timeout'){
            showErrorDialog("请求失败", "查询超时");
        }else {
            showErrorDialog('请求失败','查询返回数据异常,请重试或联系管理员确认！');
        }
        console.error(xhr);
    });

    end = new Date();
    //$.post("/client",{
    //    msg: 'comTrxSubSendPostJson '+ inObj.trx_id + ' cost: ' + (end - begin) + 'ms.'
    //});
    return outObj;
}


/**
 * 异步ajax
 * @param inObj
 * @param callback
 * @param useOverlay 显示进度遮罩层
 * @returns {*}
 */
function comTrxSubSendAsyncPostJson(inObj, callback, useOverlay) {
    var begin = new Date(), end;
    var url = "sendMessage.do";
    var strInTrx = JSON.stringify(inObj);  //把对象、数组等转化成JSON
    var outObj = null,
        $ajaxOverlay = $('#ajaxOverlay');
    $.ajax({
        type: "post",
        url: url,
        data: {
            trxId: inObj.trx_id,   //service映射ID
            strInTrx: strInTrx
        },
        beforeSend: function () {
            if(true === useOverlay){
                $ajaxOverlay.show(1);
            }
        },
        success: function (data) {
            outObj = JSON.parse(data);//JSON.parse()把对象转换成字符串。是JS方法。
            var rtn_code = outObj.rtn_code;
            if (rtn_code == "0000000") {
                if (typeof callback === "function") {
                    callback(outObj);
                }
            } else {
                showErrorDialog(rtn_code, outObj.rtn_mesg);
            }
            return outObj;
        },
        complete: function () {
            end = new Date();
            //$.post("/client",{
            //    msg: 'comTrxSubSendAsyncPostJson '+ inObj.trx_id + ' cost: ' + (end - begin) + 'ms.'
            //});

            if(true === useOverlay){
                $ajaxOverlay.hide(1);
            }
        },
        error: function () {
            showErrorDialog('请求失败','查询返回数据异常，请重试或联系管理员确认！');
            console.error("返回数据异常！");
            console.error(strInTrx);
        }
    });
    return outObj;
}

/**
 * Set jqgrid infomation
 *
 * @param {[type]}
 *            data [data]
 * @param {[type]}
 *            smpGrid [jqgrid ID] 当isIngorePage等于true时 ，忽略分页效果，显示所有记录数
 */
function setGridInfo(data, smpGrid, isIngorePage, hasPage) {
    console.time("-clearGridData");
    $(smpGrid).jqGrid("clearGridData");//清除数据
    console.timeEnd("-clearGridData");
    if (data != null && data != undefined) {
        if (data.length) {
            if (typeof(hasPage) === "undefined" || hasPage === false) {
                if ($(smpGrid).jqGrid("getGridParam", "rowNum") < data.length) {
                    $(smpGrid).setGridParam({rowNum: data.length});
                }
            }
            console.time("-setGridParam");
            $(smpGrid).jqGrid('setGridParam', {
                datatype: 'local',
                data: data
            }).trigger("reloadGrid");
            console.timeEnd("-setGridParam");
        } else {
            $(smpGrid).jqGrid("addRowData", "1", data);
        }
    }
}

function selAllGridRow($grid, flg) {
    var i,
        f = false,
        ids = $grid.getDataIDs();
    if(ids.length > 0) {
        if(true === flg){
            f = true;
        }
        $grid.jqGrid('resetSelection');
        for (i = ids.length - 1; i >= 0; i--) {
            $grid.jqGrid('setSelection', ids[i], f);
        }
    }
}

function getParameterByName(name, url) {
    if (!url) url = window.location.href;
    name = name.replace(/[\[\]]/g, "\\$&");
    var regex = new RegExp("[?&]" + name + "(=([^&#]*)|&|#|$)"),
        results = regex.exec(url);
    if (!results) return null;
    if (!results[2]) return '';
    return decodeURIComponent(results[2].replace(/\+/g, " "));
}

function comParseFloat(str) {
    if (str == null || str == undefined) {
        return 0;
    }
    return parseFloat(parseFloat(str).toFixed(3));
}

function comParseInt(str) {
    if (str == null || str == undefined || str == false) {
        return 0;
    }
    return parseInt(str, 10);// 以10进制计算
}

function getCurrentTime() {
    var data = new Date();
    var vYear = data.getFullYear();
    var vMon = data.getMonth() + 1;
    var vDay = data.getDate();
    var h = data.getHours();
    var m = data.getMinutes();
    var se = data.getSeconds();
    var stime = vYear + "-" + (vMon < 10 ? "0" + vMon : vMon) + "-" + (vDay < 10 ? "0" + vDay : vDay) + " " + (h < 10 ? "0" + h : h) + ":" + (m < 10 ? "0" + m : m) + ":" + (se < 10 ? "0" + se : se);
    return stime;
}

function comCheckMaxLenth(str, maxLen) {
    if (comGetStrLen(str) > maxLen) {
        return false;
    }
    return true;
}

/*******************************************************************************
 * 判断长度,中文长度加2，英文长度加1
 ******************************************************************************/
function comGetStrLen(str) {
    var strlen = 0;
    var l = str.length;
    for (var i = 0; i < l; i++) {
        // 全角字符
        if (str.charCodeAt(i) < 0 || str.charCodeAt(i) > 255)
            strlen = strlen + 2;
        else
            strlen++;
    }
    return strlen;
}

/*******************************************************************************
 * 判断是否包含中文
 ******************************************************************************/
function comCheckNotHasChn(str) {
    var patrn = /[u4E00-u9FA5]|[uFE30-uFFA0]/gi;
    if (patrn.exec(str)) {
        return false;
    } else {
        return true;
    }
}

//选择器    FBID,,,     字段      true/false
function addValueByDataCateFnc(selectObj, data_cate, dataItem, firstSpace) {
    var selectTxt = $(selectObj).find("option:selected").text();
    $(selectObj).empty();
    var iary = {
        dataCate: data_cate
    };
    var inTrxObj = {
        trx_id: 'XPBISDATA',
        action_flg: 'T',
        iary: [iary]
    };
    var outTrxObj = comTrxSubSendPostJson(inTrxObj);
    if (outTrxObj.rtn_code == "0000000") {
        if (firstSpace === true) {
            $(selectObj).append("<option ></option>");
        }
        var tbl_cnt = comParseInt(outTrxObj.tbl_cnt);
        if (tbl_cnt == 1) {
            $(selectObj).append("<option value=" + outTrxObj.oary[dataItem] + ">" + outTrxObj.oary[dataItem] + "</option>")
        } else if (tbl_cnt > 1) {
            for (var i = 0; i < tbl_cnt; i++) {
                $(selectObj).append("<option value=" + outTrxObj.oary[i][dataItem] + ">" + outTrxObj.oary[i][dataItem] + "</option>");
            }

        }
    }
    $(selectObj).val(selectTxt);
    // $(selectObj).select2({
    //     theme: "bootstrap"
    // });
}

function getGridNewRowID(jqGridID) {
    var rowIDs = $(jqGridID).jqGrid("getDataIDs");
    if (rowIDs.length == 0) {
        return 1;
    }
    return rowIDs[rowIDs.length - 1] + 1;
}


function getGridNewRowIDInt(jqGridID) {
    var rowIDs = $(jqGridID).jqGrid("getDataIDs");
    if (rowIDs.length == 0) {
        return 1;
    }
    return parseInt(rowIDs[rowIDs.length - 1], 10) + 1;
}

/**
 * 在Grid中查找行，找到的行背景色置为绿色，并滚动到视野内
 * @param fatherDivId grid所在的父元素ID，要能找到唯一的grid
 * @param $grid grid对象（jquery对象）
 * @param findItem 需要查找的内容在grid中的列名
 * @param findStr 需要查找的内容
 * @returns {{has: boolean, rowId: null}}
 * @private
 */
function _findRowInGrid(fatherDivId, $grid, findItem, findStr) {
    var i,
        rowIds,
        rowCnt,
        $curRowElement,
        curRowData,
        scrollHeight,
        findResult = {
            has: false,
            rowId: null
        };

    rowIds = $grid.jqGrid('getDataIDs');
    rowCnt = rowIds.length;
    if (rowCnt > 0) {
        for (i = 0; i < rowCnt; i++) {
            $curRowElement = $("#" + rowIds[i]);
            $curRowElement.removeClass('bg-found').addClass('ui-widget-content');
            curRowData = $grid.jqGrid('getRowData', rowIds[i]);
            if (!findResult.has &&
                curRowData.hasOwnProperty(findItem) &&
                curRowData[findItem] == findStr) {
                $curRowElement.removeClass('ui-widget-content').addClass('bg-found');
                findResult.has = true;
                findResult.rowId = rowIds[i];

                //scroll
                scrollHeight = ($curRowElement[0].rowIndex - 1) * $curRowElement.height();
                $('#' + fatherDivId + ' div.ui-jqgrid-bdiv').scrollTop(scrollHeight);
            }
        }
    }

    return findResult;
}

function _findRowInGrid1(fatherDivId, $grid, findItem, findStr) {
    var i,
        rowIds,
        rowCnt,
        $curRowElement,
        curRowData,
        scrollHeight,
        findResult = {
            has: false,
            rowId: null
        };

    rowIds = $grid.jqGrid('getDataIDs');
    rowCnt = rowIds.length;
    if (rowCnt > 0) {
        for (i = 0; i < rowCnt; i++) {
            $curRowElement = $("#" + rowIds[i]);
            $curRowElement.removeClass('bg-found').addClass('ui-widget-content');
            curRowData = $grid.jqGrid('getRowData', rowIds[i]);
            if (curRowData.hasOwnProperty(findItem) &&
                curRowData[findItem] == findStr) {
                $curRowElement.removeClass('ui-widget-content').addClass('bg-found');
                findResult.has = true;
                findResult.rowId = rowIds[i];

                //scroll
                scrollHeight = ($curRowElement[0].rowIndex - 1) * $curRowElement.height();
                $('#' + fatherDivId + ' div.ui-jqgrid-bdiv').scrollTop(scrollHeight);
            }
        }
    }

    return findResult;
}

function comInitSize($w, $fatherDiv) {

}

function gridcolor(grid) {

    var ids = $(grid).getDataIDs();
    for (var i = 0; i < ids.length; i++) {
        if (ids[i] % 3 == 1) {
            $("#" + ids[i]).css("background", "#FFFFCC");
        } else if (ids[i] % 3 == 2) {
            $("#" + ids[i]).css("background", "#CCFFFF");
        } else if (ids[i] % 3 == 0) {
            $("#" + ids[i]).css("background", "#FFCCFF");
        }
    }

}

/**
 * 检查权限function code
 */
function checkUserFunc(funCode, userId) {
    var qurl = "checkUserAuthority.action";
    var authoryResult = false;
    jQuery.ajax({
        type: "post",
        url: qurl,
        timeout: 60000, // TODO 1min
        data: {
            function_code: funCode,
            user_id: userId
        },
        async: false, // false代表等待ajax执行完毕后才执行alert("ajax执行完毕")语句;
        success: function (data) {
            authoryResult = data;
            if (authoryResult == "F") {
                showErrorDialog("","你没有权限执行这个操作!");
                return false;
            }
            if (authoryResult == "N"){
                showErrorDialog("","请重新登陆!");
                return false;
            }
        },
        error: function (xhr, stat, e) {
            console.error(xhr);
        }

    });
    if (authoryResult == 'Y'){
        return true;
    }else {
        return false;
    }
}

function checkUserAuthType(funCode, userId) {
    var qurl = "checkAdmin.action";
    var authoryResult = false;
    jQuery.ajax({
        type: "post",
        url: qurl,
        timeout: 60000, // TODO 1min
        data: {
            function_code: funCode,
            user_id: userId
        },
        async: false, // false代表等待ajax执行完毕后才执行alert("ajax执行完毕")语句;
        success: function (data) {
            authoryResult = data;
            if (authoryResult == "N"){
                showErrorDialog("","请重新登陆!");
                return false;
            }
        },
        error: function (xhr, stat, e) {
            console.error(xhr);
        }
    });
    return authoryResult;
}


function checkUserAuthTypeAndUserName(funCode, userId) {
    var qurl = "checkUserAuthorityAndUserName.action";
    var authoryResult = false;
    jQuery.ajax({
        type: "post",
        url: qurl,
        timeout: 60000, // TODO 1min
        data: {
            function_code: funCode,
            user_id: userId
        },
        async: false, // false代表等待ajax执行完毕后才执行alert("ajax执行完毕")语句;
        success: function (data) {
            authoryResult = data;
            if (authoryResult == "N"){
                showErrorDialog("","请重新登陆!");
                return false;
            }
        },
        error: function (xhr, stat, e) {
            console.error(xhr);
        }
    });
    return authoryResult;
}



function comResize($w, $fatherDiv, $grd) {
    var offsetBottom, divWidth;
    divWidth = $fatherDiv.width();
    offsetBottom = $w.height() - $fatherDiv.offset().top;
    $fatherDiv.height(offsetBottom);
    $grd.setGridWidth(divWidth * 0.99);
    $grd.setGridHeight(offsetBottom * 0.99 - 51);
}

/**
 * 检查是否是数字(整型+浮点)
 */
$("input[type='text'].numberCss").blur(function () {
    var $this = $(this);
    var val = $this.val();
    if (val && !ComRegex.isNumber(val)) {
        showMessengerErrorDialog("请填写数字");
        $this.val("");
    }
});
/**
 * 检查是否是数字和逗号
 */
$("input[type='text'].numCommaCss").blur(function () {
    var $this = $(this);
    var val = $this.val();
    if (val && !ComRegex.isNumComma(val)) {
        showMessengerErrorDialog("请填写数字或者英文逗号");
        //$this.val("");
        $this.attr("style", "color:red");
    } else {
        $this.attr("style", "color:black");
    }
});

function checkNumComma() {

}

/**
 * 检查是否是数字(整型+浮点)
 */
$("input[type='text'].intCss").blur(function () {
    var $this = $(this);
    var val = $this.val();
    if (val && !ComRegex.isInt(val)) {
        showMessengerErrorDialog("请填写整数");
        $this.val("");
    }
});

var ComRegex = {
    isInt: function (str) {
        return /^\d+$/.test(str);
    },
    isDouble: function (str) {
        return /^\d+\.\d+$/.test(str);
    },
    isNumber: function (str) {
        return /(^\d+$)|(^\d+\.\d+$)/.test(str);
    },
    isNumComma: function (str) {
        return /^\d+(,\d+)*$/.test(str);
    },
    isNumLetterComma: function (str) {
        return /^[A-Za-z0-9]+(,[A-Za-z0-9]+)*$/.test(str);
    }
};

// select框   data_cata   val      txt    true/false
function setSelectByDataCate($selectDom, dataCate, valProp, txtProp, withSpace) {
    var inObj = {
        trx_id: "XPBISDATA",
        action_flg: "Q",
        iary: [{
            data_cate: dataCate
        }]
    };
    var outObj = comTrxSubSendPostJson(inObj, true);
    if (outObj.rtn_code === "0000000") {
        $selectDom.empty();
        if (withSpace) {
            if (dataCate != "PRCT"){
                SelectDom.initWithSpace($selectDom, withSpace);
            }
        }
        if (dataCate == "PRCT"){
            $selectDom.append("<option value= 'null'> ---------------- </option>");
        }
        for (var i = 0; i < outObj.tbl_cnt; i++) {
            var oary = outObj.oary[i];
            SelectDom.addSelect($selectDom, oary[valProp], oary[txtProp]);
        }
    }
}

$("input[type='text']").attr("style", "border-radius:3px;");
$("select").attr("style", "border-radius:3px;");
$(".upperCassCss").keyup(function (e) {
    $(this).val($(this).val().toUpperCase());
});
